#include "GloballyAlignedSpatialDistributionModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename =
    "pcl.globally_aligned_spatial_distribution_model.json";
}

GloballyAlignedSpatialDistributionModel::
    GloballyAlignedSpatialDistributionModel()
{
}

GloballyAlignedSpatialDistributionModel&
GloballyAlignedSpatialDistributionModel::get()
{
    static GloballyAlignedSpatialDistributionModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void GloballyAlignedSpatialDistributionModel::fromJson(
    const QJsonObject& json,
    QStringList& errorList
)
{
    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
}

QJsonObject GloballyAlignedSpatialDistributionModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json.insert("pcdFile", QJsonValue(pcdFile_));

    return json;
}
